package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/*
*   自定义的类型转换器: 必须实现Spring 框架 Converter接口
* */
@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    /*
    *  source: 被转换的数据
    * */
    @Override
    public ItemType convert(String code) {
        for (ItemType value : ItemType.values()) {
             if(code.equals(String.valueOf(value.getCode()))){
                 return value;
             }
        }
        return null;
    }
}
